package com.demo.morning;

/**
 * @ClassName TestTield
 * @Description TODO
 * @Author tianqinglong
 * @Date 9:51 2022/7/13
 * @Version 1.0
 **/
//测试礼让线程
//礼让不一定成功，看CPU心情
class TestYield {
    public static void main(String[] args) {
        MyYield m = new MyYield();
        new Thread(m, "a").start();
        new Thread(m, "b").start();
    }
}

class MyYield implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "线程开始执行");
        Thread.yield();// 礼让
        System.out.println(Thread.currentThread().getName() + "线程停止执行");
    }

}
